package com.hs.controller;

import com.github.pagehelper.PageInfo;
import com.hs.entity.Consultant;
import com.hs.entity.ConsultantEvaluation;
import com.hs.service.ConsultantEvaluationService;
import com.hs.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("ConsultantEvaluation")
public class ConsultantEvaluationController {
    @Autowired
    private ConsultantEvaluationService consultantEvaluationService;
    @PostMapping
    public R addConsultantEvaluation(@RequestBody ConsultantEvaluation consultantEvaluation) {
        int i = consultantEvaluationService.addConsultantEvaluation(consultantEvaluation);
        if(i > 0){
            return R.ok();
        }else{
            return R.fail("增加失败");
        }
    }
    @DeleteMapping("{id}")
    public R deleteConsultantEvaluation(@PathVariable int id) {
        int i = consultantEvaluationService.deleteConsultantEvaluation(id);
        if(i > 0){
            return R.ok();
        }else{
            return R.fail("删除失败");
        }
    }
    @PutMapping
    public R updateConsultantEvaluation(@RequestBody ConsultantEvaluation consultantEvaluation) {
        int i = consultantEvaluationService.updateConsultantEvaluation(consultantEvaluation);
        if(i > 0){
            return R.ok();
        }else{
            return R.fail("修改失败");
        }
    }
    @GetMapping("{id}")
    public R getConsultantEvaluationById(@PathVariable int id) {
        ConsultantEvaluation consultantEvaluationById = consultantEvaluationService.getConsultantEvaluationById(id);
        return R.ok(consultantEvaluationById);
    }
    @GetMapping("getByPage")
    public R getConsultantEvaluationByPage(@RequestParam(required = false,defaultValue = "1")int pageNum, @RequestParam(required = false,defaultValue = "5")int pageSize) {
        PageInfo<ConsultantEvaluation> consultantEvaluationByPage = consultantEvaluationService.getConsultantEvaluationByPage(pageNum, pageSize);
        return R.ok(consultantEvaluationByPage);
    }
    @GetMapping("pageByConsultantId")
    public R getConsultantEvaluationByConsultantId(int consultantId,
                                                   @RequestParam(required = false,defaultValue = "1") int pageNum,
                                                   @RequestParam(required = false,defaultValue = "5")int pageSize) {
        PageInfo<ConsultantEvaluation> consultantEvaluationByConsultantId = consultantEvaluationService.getConsultantEvaluationByConsultantId(consultantId, pageNum, pageSize);
        return R.ok(consultantEvaluationByConsultantId);
    }
}
